package com.shjy.driver.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.shjy.driver.R;


/**
 * Created by zhouhuiming on 16/11/17.
 */

public class BlueToothConnectDialog extends Dialog implements View.OnClickListener{
    private View view;
    private Button buttonConnect;
    private int selectPos = -1;
    private EditText editTextPassWord;

    private View.OnTouchListener dateEditTextOnTouchListener = new EditText.OnTouchListener(){
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.setFocusable(true);
            v.requestFocus();
            InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(),0);

            return true;
        }
    };

    public BlueToothConnectDialog(Activity context, View.OnClickListener onClickListener) {
        super(context);
        view = LayoutInflater.from(context).inflate(R.layout.dialog_connect_bluetooth,null);
        editTextPassWord = (EditText) view.findViewById(R.id.editTextPassWord);
        editTextPassWord.setOnTouchListener(dateEditTextOnTouchListener);
        buttonConnect = (Button) view.findViewById(R.id.buttonConnect);
        buttonConnect.setOnClickListener(onClickListener);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = 286;
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(429,330);
        getWindow().setAttributes(params);
        setContentView(view,layoutParams);
    }

    public String getPassWord(){
        return editTextPassWord.getText().toString();
    }

    public int getSelectPos() {
        return selectPos;
    }

    public void setSelectPos(int selectPos) {
        this.selectPos = selectPos;
    }

    @Override
    public void onClick(View v) {
        dismiss();
    }
}
